package com.dragon.repository.mapper;

import com.dragon.repository.entity.ContractArticle;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 条款 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-07-21
 */
@Mapper
public interface ContractArticleMapper extends BaseMapper<ContractArticle> {

    @Select("SELECT a.* FROM dragon_contract_article a " +
            "INNER JOIN dragon_contract_article_son b on a.id = b.article_id " +
            "INNER JOIN dragon_contract c on b.contract_id = c.id WHERE c.id = #{id} ")
    ContractArticle selectArticleList(Integer id);

    @Update("UPDATE dragon_contract_article SET is_default = CASE is_default WHEN 0 THEN 1 WHEN 1 THEN 0 END WHERE id= #{id}")
    void setUpDefault(Integer id);
}
